var MY_SEWAGE_COM = (function() {

	function getThead(){
		var e='<tr>\
				<th width="5%" class="text-center">机构名/科室</th>\
				<th width="5%" class="text-center">检查日期</th>\
   				<th width="4%" class="text-center">AM/PM</th>\
   				<th width="4%" class="text-center">状态</th>\
   				<th width="6%" class="text-center">状态说明</th>\
				<th width="4%" class="text-center">余氯结果</th>\
				<th width="4%" class="text-center">消毒剂投放</th>\
				<th width="5%" class="text-center">消毒剂</th>\
				<th width="5%" class="text-center">检测时间</th>\
				<th width="5%" class="text-center">操作人</th>\
				<th width="4%" class="text-center">申述状态</th>\
				<th width="6%" class="text-center">申述内容</th>\
				<th width="6%" class="text-center">照片</th>\
				<th width="6%" class="text-center">处理意见</th>\
				<th width="4%" class="text-center">处理人</th>\
				<th width="5%" class="text-center">操作</th>\
   			</tr>';
		return e;
	}
	
	/**
	 * 查看明细
	 * */
	function loadDetailItem(params,$thead,$tbody){
		
		$thead.empty();
		$tbody.empty();
		
		$thead.append(getThead());
		
		WeKnow.loading();
		
		$.ajax({ 
	        type: "POST", 
	        url: "invs_sewage.do/load_detail", 
	        dataType: "json",
	        contentType:"application/json",
	        data: JSON.stringify(params),
	        async: true,//异步调用
	        success: function(data) {
	        	
	        	WeKnow.closeLoading();
	        	
				if (!WeKnow.filterAjaxResult(data)) return false; // session过期check
	        	
	        	if (data.errcode == 0) {
	        		// 把取到的结果放到
	        		var e = '';
	        		
	        		if ( 'datalist' in data && data.datalist.length == 0 ){
	        			WeKnow.errorMsg('没有查询到医疗机构数据');
	        			return;
	        		}
	        		
	        		$(data.datalist).each(function( idx,_a){
	        			e+='<tr ';
							e+= ' data-illegal_id="' + _a.id + '"';
							if ( _a.appeal && _a.appeal.appealAtta ){ //申诉图片
    							e+= ' data-appeal_atta="' + _a.appeal.appealAtta + '"';
    						}
						e+='>';
							// 机构名/科室
							e+='<td class="text-center">'+  _a.institutionShortName + '</td>';
		        			// 检查日期
	        				e+='<td class="text-center">'+  _a.serialDate + '</td>';
	        				// 上午下午
	        				e+='<td class="text-center">'+ (_a.amPm==0?'AM':'PM') + '</td>';
	        				// 状态
	        				e+='<td class="text-center">'+ (_a.checkSt==0?'正常':'<font style="color:red;">异常</font>') +  '</td>';
	        				// 状态说明
	        				e+='<td class="text-center">'+ (_a.message==null?'-':_a.message) + '</td>';
	        				// 余氯结果
	        				e+='<td class="text-center">'+ (_a.disinfectantEntity.remainingChlorine == null?'-': _a.disinfectantEntity.remainingChlorine  + 'mg/L')+'</td>';
	        				// 消毒剂投放
	        				e+='<td class="text-center">'+  (_a.disinfectantEntity.isAdd == 1?'是':'否') + '</td>';
	        				// 消毒剂
	        				e+='<td class="text-center">'+  (_a.disinfectantEntity.disinfectantName == null?'':_a.disinfectantEntity.disinfectantName) + '</td>';
	        				// 检测时间
	        				e+='<td class="text-center">'+  (_a.disinfectantEntity.checkTm == null?'-':new Date(_a.disinfectantEntity.checkTm).format('hh:mm')) + '</td>';
	        				// 操作人
	        				e+='<td class="text-center">'+ (_a.doctorName == null?'':_a.doctorName) + '</td>';
	        				// 申诉状态
        					if (_a.appeal){
        						e+='<td class="text-center">'+ MY_APPEAL.getAppealStTxt(_a.appeal.appealSt) +'</td>';// 申述状态
        						e+='<td class="text-center">'+ (_a.appeal.appeal==null?'-':_a.appeal.appeal) +'</td>';// 申述内容
        						
        						// 申述图片
    							if ( _a.appeal && _a.appeal.appealAtta ){
    								e+='<td class="text-center"><button type="button" name="showAppealAtta" class="btn btn-default btn-sm">查看</button></td>';
    							} else {
    								e+='<td class="text-center">-</td>';
    							}
        						
        						e+='<td class="text-center">'+ (_a.appeal.feedback==null?'-':_a.appeal.feedback) +'</td>';//处理意见	
        						e+='<td class="text-center">'+ (_a.appeal.supervisorName==null?'-':_a.appeal.supervisorName) +'</td>';	// 处理人
        						// 操作按钮区  根据申诉表的信息控制显示的按钮
        						if ( _a.appeal.appealSt == 1){
									e+='<td class="text-center"><button type="button" name="check" class="btn btn-default btn-sm">申诉处理</button></td>';
								} else if ( _a.appeal.appealSt == 0 ) {
									e+='<td class="text-center"><button type="button" name="closeIllegal" class="btn btn-default btn-sm">取消异常</button></td>';
								} else {
									e+='<td class="text-center">-</td>';
								}
        					
        					}else{
        						e+='<td class="text-center">-</td>';
        						e+='<td class="text-center">-</td>';
        						e+='<td class="text-center">-</td>';
        						e+='<td class="text-center">-</td>';
        						e+='<td class="text-center">-</td>';
        						e+='<td class="text-center">-</td>';
        					}
	        			e+='</tr>';
	        		});
	        		$tbody.append(e);
	        		
	        	} else if (data.errcode == -1 ) {
	        		WeKnow.errorMsg( data.errMsg );
	        	} else {
	        		WeKnow.systemMsg('查询失败，请重新登录后再试');
	        	}
	        }
		});
	}
	return {
		loadDetailItem:loadDetailItem
	}
})();
